#coding=utf-8
"""
Author:杭州多测师_付佳美
Time:2025/5/7 10:00
website:https://duoceshi.net
"""

import unittest
from time import *

from selenium import webdriver
driver = webdriver.Chrome()

class Basepage(unittest.TestCase):

    @classmethod
    def set_driver(cls,driver):
        cls.driver = driver

    @classmethod
    def get_driver(cls):
        return cls.driver

    @classmethod
    def find_element(cls,element):
        type = element[0]
        value = element[1]
        if type == "id":
            elem = cls.driver.find_element_by_id(value)
        elif type == "xpath":
            elem = cls.driver.find_element_by_xpath(value)
        elif type == "name":
            elem = cls.driver.find_element_by_name(value)
        elif type == 'class':
            elem = cls.driver.find_element_by_class_name(value)
        elif type == "css":
            elem = cls.driver.find_element_by_css_selector(value)
        elif type == "link_text":
            elem = cls.driver.find_element_by_link_text(value)
        elif type == "partial":
            elem = cls.driver.find_element_by_partial_link_text(value)
        else:
            raise ValueError("定位方式有误请输入正确的参数")
        return elem

    @classmethod
    def sendKeys(cls,elem,text):
        return elem.send_keys(text)

    @classmethod
    def click(cls,elem):
        return elem.click()

    @classmethod
    def wait(cls,sec):
        return cls.driver.implicitly_wait(sec)

    @classmethod
    def frame(cls,elem):
        return cls.driver.switch_to.frame(elem)

    @classmethod
    def outframe(cls):
        return driver.switch_to.default_content()

    @classmethod
    def sleep(cls,sec):
        return sleep(sec)

    @classmethod
    def get_text(cls,elem):
        value = Basepage.find_element(elem).text
        return value
if __name__ == '__main__':
    from selenium import webdriver
    driver = webdriver.Chrome()
    driver.get("http://www.baidu.com")
    driver.maximize_window()
    baidu_input =('id','kw')
    Basepage.sleep(3)
    elem = Basepage.find_element(baidu_input)
    Basepage.sendKeys(elem,'dcs')












